package com.zrrd.jt_admin.set.express.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zrrd.jt_admin.common.bo.ExpressBo;
import com.zrrd.jt_admin.common.entity.Express;
import com.zrrd.jt_admin.common.entity.ExpressValue;
import com.zrrd.jt_admin.set.express.mapper.ExpressMapper;
import com.zrrd.jt_admin.set.express.service.ExpressService;
import com.zrrd.jt_admin.set.express.service.ExpressValueService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wanjl
 * @since 2024-07-10
 */
@Service
public class ExpressServiceImpl extends ServiceImpl<ExpressMapper, Express> implements ExpressService {

    @Resource
    private ExpressValueService expressValueService;

    /**
     * 查询物流模板(包括物流信息)
     *
     * @return
     */
    @Override
    public List<ExpressBo> findAll() {
        List<ExpressBo> expressBoList = list().stream().map(express -> {
            ExpressBo expressBo = new ExpressBo();
            BeanUtils.copyProperties(express, expressBo);
            List<ExpressValue> list = expressValueService.lambdaQuery().eq(ExpressValue::getExpressId, express.getId()).list();
            expressBo.setList(list);
            return expressBo;
        }).collect(Collectors.toList());

        return expressBoList;
    }
}
